package com.putao.album.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.putao.album.fileupload.FileUploadManager;
import com.putao.album.util.CommonUtils;
import com.putao.album.util.Loger;

/**
 * Created by chen on 15-6-3.
 */
public class NetworkReceiver  extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

        Loger.d("chen+++NetworkReceiver+++networkInfo:" + networkInfo);

        if (networkInfo != null) {
            if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                if (networkInfo.isAvailable()) {
                    if (CommonUtils.isBackgroundUploadOpen()) {
                        FileUploadManager.getIntance().startUploadCurrentChildUnfinished(CommonUtils.getBabyId());
                    }
                }
            }
        }
    }
}
